package com.pms.init.base;

import org.springframework.stereotype.Component;

import com.espirit.eap.manager.ModelBuilderSupport;
import com.espirit.eap.pagelayout.FunctionButton;
import com.espirit.eap.pagelayout.ModelField;
import com.espirit.eap.pagelayout.Page;
import com.espirit.eap.pagelayout.PageUpgrade;
import com.googlecode.cswish.annotation.Dependence;

@Dependence(value={
		"com.pms.init.base.I18nBuilder",
})
@Component
public class PageBuilder extends ModelBuilderSupport {
	
	private FunctionButton importLayout = null;
	
	private FunctionButton exportLayout = null;
	
	private FunctionButton exportLayoutWitData = null;
	
	@Override
	public boolean init() {
		return super.setClass(Page.class, "Page Layout", "页面自定义") ;
	}
	
	@Override
	public void buildFields() {
		super.buildFields();
		addModelField("id","id", "id");
		addModelField("path", "path", "路径");
		addModelField("method", "method", "方法");
		addModelField("freeAccess", "free access", "自由访问");
	}
	
	@Override
	public void prepareLayoutElements() {
		importLayout = super.createFunctionButton("_importLayout", "Import Layout", "导入布局", PageUpgrade.class, "_importLayout");
		updateObject(importLayout);
		exportLayout = super.createFunctionButton("exportLayout", "Export Layout", "导出布局", PageUpgrade.class,"exportLayout");
		updateObject(exportLayout);
		exportLayoutWitData = super.createFunctionButton("exportLayoutWithData", "Export Layout", "导出布局及数据", PageUpgrade.class,"exportLayoutWithData");
		updateObject(exportLayoutWitData);
		
		ModelField mfName = getModelField("i18n");
		ModelField mfPath = getModelField("path");
		ModelField mfMethod = getModelField("method");
		ModelField mfFreeAccess = getModelField("freeAccess");
		ModelField custom = getModelField("layout.customVersion");
		addSearchField(mfName, mfPath,mfMethod);
		addListField(mfName, mfPath,mfMethod);
		addDetailField(mfPath, mfMethod,mfFreeAccess, custom);
	}
	
	@Override
	protected void setDefaultLayoutButtons() {
		super.setDefaultLayoutButtons();
		addExtraButton(importLayout);
		addExtraButton(exportLayout);
		addExtraButton(exportLayoutWitData);
	}
}
